package com.biz.primus.ms.coupon.config;

import java.util.Map;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;

/**
 * 优惠券模块配置
 *
 * @author david-liu
 */
@Slf4j
public final class CouponModuleConfig {

    private Properties properties = new Properties();

    private static volatile CouponModuleConfig instance;

    private CouponModuleConfig() {
    }

    public static CouponModuleConfig getInstance() {
        if (instance == null) {
            synchronized (CouponModuleConfig.class) {
                if (instance == null) {
                    instance = new CouponModuleConfig();
                }
            }
        }
        return instance;
    }

    public void clear() {
        properties.clear();
    }

    public void putAll(Map<String, String> t) {
        properties.putAll(t);
    }

    public void putAll(Properties p) {
        properties.putAll(p);
    }

    public void put(String key, String value) {
        properties.put(key, value);
    }

    public int size() {
        return properties.size();
    }

    public int getPreBuildCouponSizeLimit() {
        String preBuildCouponSizeLimit = this.properties.getProperty("coupon.pre.build.size.limit");
        Integer defaultPreBuildCouponSizeLimit = 10000;
        if (NumberUtils.isCreatable(preBuildCouponSizeLimit)) {
            return Integer.valueOf(preBuildCouponSizeLimit);
        }
        return defaultPreBuildCouponSizeLimit;
    }
}
